package com.xiaobai.java_core.swing;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author 王天文
 * @Date 2024/12/12 9:14
 * @Description:
 */
public class PaneDialogDemo {

    public static void main(String[] args) {
        // 获取屏幕的宽度和高度
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;

        int numPopups = 3; // 定义要弹出的弹窗数量
        for (int i = 0; i < numPopups; i++) {

            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    // 随机生成弹窗的坐标位置（这里示例简单的范围，可根据实际屏幕大小等调整更合理范围）
                    Random random = new Random();
                    int x = random.nextInt(screenWidth - 300);
                    int y = random.nextInt(screenHeight - 200);
                    Point location = new Point(x, y);

                    // 创建并配置弹窗
                    JOptionPane pane = new JOptionPane("你该下班了！", JOptionPane.INFORMATION_MESSAGE);
                    JDialog dialog = pane.createDialog(null, "温馨提示");

                    dialog.setLocation(location);
                    dialog.setSize(250, 150);
                    dialog.setVisible(true);
                }
            });
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            thread.start();
        }
    }
}
